package ru.urfc.portal.ui.client.googlets.client;

import ru.urfc.portal.ui.client.BaseDocument;
import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.DocumentResolverGwt;
import ru.urfc.portal.ui.client.widgets.DocumentButtons;
import ru.urfc.portal.ui.client.widgets.DocumentHeader;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Widget;

public class DocumentEdit extends BaseGooglet {

	interface Binder extends UiBinder<Widget, DocumentEdit> {}
	private static Binder binder = GWT.create(Binder.class);
	private static DocumentResolverGwt documentResolver = new DocumentResolverGwt();
	
	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		String typeCode = getDocumentType();
		if (typeCode == null) {
			return;
		}
		BaseDocument document = documentResolver.document(typeCode);
		if (document != null) {
			DocumentHeader header = new DocumentHeader();
			DocumentButtons buttons = new DocumentButtons();
			document.setHeader(header);
			addGooglet(header);
			addGooglet(document);
			addGooglet(buttons);
			buttons.bind(document);
		}
	}
	

}